package com.fnst.caesar;

import java.io.*;
import java.util.*;

import org.apache.poi.hssf.usermodel.*;

public class ExcelUtil
{
	static public List<ApplyInfo> ExcelReadUtil(String path) throws Exception
	{
		List<ApplyInfo> result = new ArrayList<ApplyInfo>();
		InputStream is = new FileInputStream(path);
		HSSFWorkbook wb = new HSSFWorkbook(is);
		HSSFSheet sh = wb.getSheetAt(0);
		int rowNum = sh.getLastRowNum();
		for(int i = 1; i <= rowNum; i++)
		{
			HSSFRow row = sh.getRow(i);
			int cellNum = row.getLastCellNum();
			String[] content = new String[3];
			for(int j = 0; j < cellNum; j++)
			{
				HSSFCell cell = row.getCell(j);
				if(cell.getCellType() != HSSFCell.CELL_TYPE_NUMERIC)
				{
					HSSFRichTextString rts = cell.getRichStringCellValue();
					content[j] = rts.getString();
				}
				else
				{
					double tmp = cell.getNumericCellValue();
					int real = (int)Math.floor(tmp);
					content[j] = Integer.toString(real);	
				}
			}
			ApplyInfo d = new ApplyInfo(content[0],content[1],content[2]);
			result.add(d);
		}
		is.close();
		return result;
	}
}